export default {
    data() {

    },
    methods: {
        //转时间戳
        changeTime(val) {
            return new Date(parseInt(val) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
        },
        //转时间戳3
        parseTime(time, cFormat) {
            if (arguments.length === 0) {
                return null
            }
            const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
            let date
            if (typeof time === 'object') {
                date = time
            } else {
                if (('' + time).length === 10) time = parseInt(time) * 1000
                date = new Date(time)
            }
            const formatObj = {
                y: date.getFullYear(),
                m: date.getMonth() + 1,
                d: date.getDate(),
                h: date.getHours(),
                i: date.getMinutes(),
                s: date.getSeconds(),
                a: date.getDay()
            }
            const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
                let value = formatObj[key]
                if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
                if (result.length > 0 && value < 10) {
                    value = '0' + value
                }
                return value || 0
            })
            return time_str
        },
        //转时间戳带横杠
        changeTime3(val) {
            return new Date(parseInt(val) * 1000).toLocaleDateString().replace(/\//g, '-');
        },
        //把年月日转成时间戳
        toDate(val) {
            return new Date(val.replace(/-/g, '/')) * 1000 / 1000000;
        },
        // 新窗口预览大图
        loadImg(url) {
            var newwin = window.open()
            newwin.document.write("<div style='width:100%;height:100%;background:black;opacity:.8;position:relative;'></div><div style='width:100%;z-index:100;position:absolute;text-align:center;top:calc(50% - 300px)'><img src=" + url + " style='height:600px;'/></div>")
        },
        // 手机号验证
        IsMobile(phone) {
            var rules = /^((\+?86)|(\(\+86\)))?(13[0123456789][0-9]{8}|14[0123456789][0-9]{8}|15[0123456789][0-9]{8}|17[0123456789][0-9]{8}|18[0123456789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/;
            return rules.test(phone);
        },
        //表格改变颜色
        rowClassName(row, index) {
            if (index % 2 == 0) {
                return 'demo-table-info-row';
            } else {
                return 'demo-table-error-row';
            }
            return '';
        },
        //校验只要是数字（包含正负整数，0以及正负浮点数）就返回true
        isNumber(val){
            var regPos = /^\d+(\.\d+)?$/; //非负浮点数
            if(regPos.test(val)){
                return true;
            }else{
                return false;
            }
        }
    },
    created() {

    }
}